import os
import json

def update_label_paths(input_file):
    base_dir = r"D:\songlin\data\9.公开数据集\身份证号识别\IDcard"
    with open(input_file, 'r', encoding='utf-8') as f:
        lines = f.readlines()
    
    with open(input_file, 'w', encoding='utf-8') as f:
        for line in lines:
            if line.strip():
                parts = line.split('\t')
                if len(parts) == 2:
                    # 提取文件名
                    filename = os.path.basename(parts[0])
                    # 构建新路径
                    new_path = os.path.join(base_dir, filename)
                    # 保留原有JSON数据
                    json_data = parts[1].strip()
                    f.write(f"{new_path}\t{json_data}\n")
                else:
                    f.write(line)

# 使用示例
update_label_paths("label.txt")